package com.nameli.admin.service.impl.system;

import com.nameli.SIM.bean.entity.sys.SysRole;
import com.nameli.SIM.mapper.SysRoleMapper;
import com.nameli.SIM.util.EmptyUtil;
import com.nameli.admin.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author NAME-L
 * @Description 角色业务实现类
 * @className SysRoleServiceImpl
 * @date 2022-01-21 10:41:09
 */
@Component
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    private SysRoleMapper roleMapper;

    /**
     * 根据用户ID查询角色
     * @param userId 用户id
     * @return 角色列表
     */
    @Override
    public Set<String> selectRolePermissionByUserId(Long userId) {
        List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
        Set<String> permsSet = new HashSet<>();
        for (SysRole perm : perms)
        {
            if (EmptyUtil.isNotEmpty(perm))
            {
                permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
            }
        }
        return permsSet;
    }
}
